import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { MessageEntity } from "./message.entity";

export interface UserRo {
  list: MessageEntity[];
  count: number;
}
@Injectable()
export class MessageService {
  constructor( @InjectRepository(MessageEntity)
  private MessageRepository:Repository<MessageEntity>){}

  async create(body:any) {
    console.log(body);
    const data = body
    const count = await this.MessageRepository.count()
    data.id = count + 1
    data.date = new Date()
    data.read = 0
    this.MessageRepository.save(data)
    return {
        status:0,
        title:"发送成功"
    }
  }

  async findAll() {
    const list = await this.MessageRepository.find()
    const count = await this.MessageRepository.count()
    return {
      list,
      count
    }
  }

}
